<template>
	<view class="flash-sale">
		<view class="saleBox"></view>
		<view class="tab-block">
			<view class="item" @tap="tabChange(0)">
				<view class="title" :class="indexCurrent==0?'item-check-color':''">正在抢购</view>
				 
			</view>

			<view class="item" @tap="tabChange(1)">
				<view class="title" :class="indexCurrent==1?'item-check-color':''">即将开始</view>
				 
			</view>

			<view class="item" @tap="tabChange(2)">
				<view class="title" :class="indexCurrent==2?'item-check-color':''">已结束</view>
				 
			</view>
		</view>
		
		<view class="content" v-if="seckillLst.length>0"> 
			<block v-for="(item,index) in seckillLst"  >
				<block v-for="(goods,goodIndex) in item.seckillCommodityList" :key="goodIndex">
					<view class="item" @tap="itemClick(goods,item)">
						<view class="img">
							<image :src="goods.main_image" class="auto-img img-radius"></image>
							<view class="time-count-position">
								<template v-if="seckillType==0">
									<uni-countdown :show-day="true" :day="time(item.end_time,'day')" color="#fff"
										splitorColor='#fff' :hour="time(item.end_time,'hour')"
										:minute="time(item.end_time,'minute')" :second="time(item.end_time,'second')"
										:fontSize='10' ref="countDownRef" @timeup='countTwoEnd'></uni-countdown>
								</template>
								<template v-if="seckillType==1">
									<uni-countdown :show-day="true" :day="timeTwo(item.begin_time,'day')" color="#fff"
										splitorColor='#fff' :hour="timeTwo(item.begin_time,'hour')"
										:minute="timeTwo(item.begin_time,'minute')"
										:second="timeTwo(item.begin_time,'second')" :fontSize='10' ref="countDownRef"
										@timeup='countTwoEnd'></uni-countdown>
								</template>
								<view style="font-size: 20rpx;color: #fff;padding: 6rpx 12rpx;" v-if="seckillType==2">
									已结束
								</view>
							</view>
						</view>
						<view class="right-info">
							<view class="title">{{goods.title}}</view>
							<view class="nums-block">
								<view class="nums">
									<span>¥</span>
									<view class="line-price">{{goods.line_price||0}}</view>
									<span>¥</span>{{goods.seckill_price/100}}
								</view>
								<view class="buy-img center">
									<image :src="buyIcon" class="auto-img"></image>
								</view>
							</view>
						</view>
					</view>
				</block>
			</block>
		</view>
		<view class="no-emty" v-if="seckillLst.length==0" style="font-size: 26rpx;color: #999;">暂无数据</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				indexCurrent: 0,
				buyIcon: require('@/static/category/buy.png'),
				tabCurrent: 'ing',
				seckillType: 0,
				tabList: [{
						id: 'ing',
						title: '进行中',
						status: 0

					},
					{
						id: 'nostart',
						title: '即将开始',
						status: 1
					},
					{
						id: 'ended',
						title: '已结束',
						status: 2
					},
				],
				seckillLst: [],
				//后面加
				scrollLeft: 0,
				active: 0,
				timeList: [{
						time: "07:00",
						id: 114,
						state: '已结束',
						stop: '1668132000'
					},
					{
						time: "08:00",
						id: 114,
						state: '已结束',
						stop: '1668132000'
					},
					{
						time: "09:00",
						id: 114,
						state: '已结束',
						stop: '1668132000'
					},
					{
						time: "10:00",
						id: 114,
						state: '已结束',
						stop: '1668132000'
					},
					{
						time: "11:00",
						id: 114,
						state: '已结束',
						stop: '1668132000'
					},
				]
			}
		},																																																																																																																																																																												
		onLoad() {
			this.getSeckillListFun()
		},
		computed: {
			time() {
				return (endTime, val) => {
					let str= this.$tools.getUnixToDate('yyyy-mm-dd',endTime)
					let strTwo=str.replace(/-/g, "/")
					let times=this.$tools.getDHS(strTwo)
					return times[val]
				}
			},
			timeTwo() {
				return (beginTime, val) => {
					let str= this.$tools.getUnixToDate('yyyy-mm-dd',beginTime)
					let strTwo=str.replace(/-/g, "/")
					let times=this.$tools.getDHS(strTwo)
					return times[val]
				}
			}
		},
		methods: {
			onTab(id, status) {
				this.tabCurrent = id;
				this.status = status;
				this.seckillType = status
				this.getSeckillListFun()
			},
			getSeckillListFun() {
				this.$http('goods.getSeckillList', {
					type: this.seckillType,
				}).then(res => {
					if (res.code == 200) {
						this.seckillLst = res.data.list
					}
				})
			},
			tabChange(e){
				this.indexCurrent = e
				this.seckillType=e
				this.getSeckillListFun()
			},
			countTwoEnd() {
				this.getSeckillListFun()
			},
			itemClick(goods, item) {
				if (this.seckillType == 0) {
					this.goShopDetail(goods, item)
				} else if (this.seckillType == 1) {
					this.$tools.showMsg('商品即将开始')
				} else {
					this.$tools.showMsg('限时秒杀已结束')
				}
			},
			goShopDetail(goods, item) {
				uni.setStorageSync('seckillPrice',goods.seckill_price)
				uni.setStorageSync('seckillPrice',goods.seckill_price)
				
				
				uni.navigateTo({
					url: '/pages/shopDetail/shopDetail?goodsId=' + goods.commodity_id + '&endTime=' + item.end_time+ '&seckill_id=' + goods.id
				})
			},
			settimeList(item, index) {
				this.active = index
			}
		}
	}
</script>

<style lang="scss" scoped>
	.flash-sale .header {
		width: 710rpx;
		// height: 300rpx;
		// margin: -215rpx auto 0 auto;
		border-radius: 20rpx;
	}

	.flash-sale .header image {
		width: 100%;
		height: 100%;
		border-radius: 20rpx;
	}

	.flash-sale .seckillList {
		padding: 0 20rpx;
		display: flex;
		align-items: center;
	}

	.flash-sale .seckillList .priceTag {
		width: 75rpx;
		height: 70rpx;
	}

	.flash-sale .seckillList .priceTag image {
		width: 100%;
		height: 100%;
	}

	.flash-sale .timeLsit {
		width: 610rpx;
		white-space: nowrap;
		margin: 10rpx 0;
	}

	.flash-sale .timeLsit .item {
		display: inline-block;
		font-size: 20rpx;
		color: #666;
		text-align: center;
		padding: 11rpx 0;
		box-sizing: border-box;
		height: 96rpx;
		margin-right: 35rpx;
		margin-left: 20rpx;
	}

	.flash-sale .timeLsit .item .time {
		font-size: 36rpx;
		font-weight: 600;
		color: #333;
	}

	.flash-sale .timeLsit .item.on .time {
		color: #E93323;
	}

	.flash-sale .timeLsit .item.on .state {
		width: 90rpx;
		height: 30rpx;
		border-radius: 15rpx;
		background: linear-gradient(90deg, rgba(252, 25, 75, 1) 0%, rgba(252, 60, 32, 1) 100%);
		color: #fff;
	}

	.flash-sale .countDown {
		height: 92rpx;
		border-bottom: 1rpx solid #f0f0f0;
		margin-top: -14rpx;
		font-size: 28rpx;
		color: #282828;
	}

	.flash-sale .countDown .num {
		font-size: 28rpx;
		font-weight: bold;
		background-color: #ffcfcb;
		padding: 4rpx 7rpx;
		border-radius: 3rpx;
	}

	.flash-sale .countDown .text {
		font-size: 28rpx;
		color: #282828;
		margin-right: 13rpx;
	}

	.flash-sale .list .item {
		height: 230rpx;
		position: relative;
		width: 710rpx;
		margin: 0 auto 20rpx auto;
		background-color: #fff;
		border-radius: 20rpx;
		padding: 0 25rpx;
	}

	.flash-sale .list .item .pictrue {
		width: 180rpx;
		height: 180rpx;
		border-radius: 10rpx;
	}

	.flash-sale .list .item .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 10rpx;
	}

	.flash-sale .list .item .text {
		width: 460rpx;
		font-size: 30rpx;
		color: #333;
		height: 166rpx;
	}

	.flash-sale .list .item .text .name {
		width: 100%;
	}

	.flash-sale .list .item .text .money {
		font-size: 30rpx;
		color: #E93323;
	}

	.flash-sale .list .item .text .money .num {
		font-size: 40rpx;
		font-weight: 500;
		font-family: 'Guildford Pro';
	}

	.flash-sale .list .item .text .money .y_money {
		font-size: 24rpx;
		color: #999;
		text-decoration-line: line-through;
		margin-left: 15rpx;
	}

	.flash-sale .list .item .text .limit {
		font-size: 22rpx;
		color: #999;
		margin-bottom: 5rpx;
	}

	.flash-sale .list .item .text .limit .limitPrice {
		margin-left: 10rpx;
	}

	.flash-sale .list .item .text .progress {
		overflow: hidden;
		background-color: #FFEFEF;
		width: 260rpx;
		border-radius: 18rpx;
		height: 18rpx;
		position: relative;
	}

	.flash-sale .list .item .text .progress .bg-reds {
		width: 0;
		height: 100%;
		transition: width 0.6s ease;
		background: linear-gradient(90deg, rgba(233, 51, 35, 1) 0%, rgba(255, 137, 51, 1) 100%);
	}

	.flash-sale .list .item .text .progress .piece {
		position: absolute;
		left: 8%;
		transform: translate(0%, -50%);
		top: 49%;
		font-size: 16rpx;
		color: #FFB9B9;
	}

	.flash-sale .list .item .grab {
		font-size: 28rpx;
		color: #fff;
		width: 150rpx;
		height: 54rpx;
		border-radius: 27rpx;
		text-align: center;
		line-height: 54rpx;
		position: absolute;
		right: 30rpx;
		bottom: 30rpx;
	}

	.flash-sale .saleBox {
		width: 100%;
		height: 38rpx;
		background: rgba(233, 51, 35, 1);
		border-radius: 0 0 50rpx 50rpx;
	}

	.content {
		margin: 40rpx 32rpx 40rpx 32rpx;
	}

	.item {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 188rpx;
		margin: 6rpx 0rpx 24rpx 0rpx;
	}

	.img {
		position: relative;
		flex: none;
		width: 188rpx;
		height: 188rpx;
		border-radius: 8rpx;

		.time-count-position {
			position: absolute;
			left: 0;
			top: 0;
			border-radius: 8rpx;
			background: rgba(203, 60, 40, 1);
		}
	}

	.right-info {
		flex: auto;
		margin-left: 16rpx;
		display: flex;
		flex-direction: column;
		height: 100%;
		// align-items: center;
		justify-content: flex-start;

		.title {
			margin-top: 10rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: rgba(0, 0, 0, 1);
			height: 144rpx;
		}

		.nums-block {
			width: 100%;
			height: 44rpx;
			flex: none;
			display: flex;
			align-items: center;

			.nums {
				color: rgba(203, 60, 40, 1);
				flex: auto;
				font-size: 32rpx;
				display: flex;
				align-items: center;

				span {
					font-size: 22rpx;

				}

				.line-price {
					text-decoration: line-through;
					margin-right: 20rpx;
				}
			}

			.buy-img {
				flex: none;
				width: 44.19rpx;
				height: 44rpx;
				border-radius: 50%;

			}
		}
	}

	.tab-block {
		 margin-top: 24rpx;
		display: flex;
		align-items: center;
		justify-content: space-evenly;
		height:70rpx;
	 
		.item {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			font-size: 30rpx;
			 
			font-weight: 500;
			color: rgba(0, 0, 0, 1);
		}

		.item-check-color {
			color: rgba(203, 60, 40, 1);
		}

		.status-block {
			margin-top: 18rpx;
			width: 94rpx;
			height: 36rpx;
			height: 36rpx;
			border-radius: 382rpx;
			background: rgba(203, 60, 40, 1);
			font-size: 22rpx;
			font-weight: 400;
			color: rgba(255, 255, 255, 1);
			justify-content: center;
		}

		.time-block {
			margin-top: 18rpx;
			width: 94rpx;
			height: 36rpx;
		}
	}
	.no-emty {
		margin-top: 20rpx;
		text-align: center;
		width: 100%;
		font-size: 28rpx;
	}
</style>
